package com.hxgz.form;


import com.fasterxml.jackson.annotation.JsonIgnore;
import org.springframework.cglib.beans.BeanMap;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: demo-root
 * @description:
 * @author: 陈湃
 * @create: 2018-12-14 08:03
 **/
public class ReqForm<T> {
    private static final long serialVersionUID = 1L;
    @Valid
    private T data;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    /**
     * 将参数转化为Map
     *
     * @return
     */
    @JsonIgnore
    public Map<Object, Object> getMapParam() {
        Map<Object, Object> map = new HashMap<>();
        if (data != null) {
            BeanMap beanMap = BeanMap.create(data);
            for (Object key : beanMap.keySet()) {
                map.put(key + "", beanMap.get(key));
            }
        }
        return map;
    }


}

